<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2016-8-16
 * Func   后台入口
 */
session_start();
header('Content-Type:text/html; charset=UTF-8');
date_default_timezone_set('PRC');
error_reporting(E_ERROR | E_WARNING | E_PARSE);

define('IN_YuLin', true);
define('TIMESTAMP', time());
define('IS_POST',(strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' ? true : false));
define('ROOT_PATH', str_replace('\\', '/', dirname(__FILE__) . '/')); //根目录
define('DATA_PATH', ROOT_PATH . 'data/'); //数据目录
define('LIB_PATH', ROOT_PATH . 'lib/');  //类库文件

include_once LIB_PATH . 'common.inc.php';
require_once LIB_PATH . 'protect.php';
include_once LIB_PATH . 'common.func.php';

//  m、c、a、用来判断路由
$m = NoBadStr($_REQUEST['m']);
$c = NoBadStr($_REQUEST['c']);
$a = NoBadStr($_REQUEST['a']);
!$m && $m = 'index';
!$c && $c = 'index';
!$a && $a = 'index';
if (!in_array($m, array('api'))){
    !file_exists(ROOT_PATH.'module/wap/'.$m.'/'.$c.'.inc.php') && exit('No input file...');
}else{
    !file_exists(ROOT_PATH.'module/'.$m.'/'.$c.'.inc.php') && exit('No input file...');
}
//	数据库
include(LIB_PATH.'class/Db.class.php');
$db = new DB($_config['db']);

//	模版引擎
include(LIB_PATH.'class/Ytemplate.class.php');
$tpl = new Ytemplate();
$tpl->templateCompile = DATA_PATH.'compile/wap';
$tpl->templateDir = ROOT_PATH.'template/wap';
$tpl->templateExt = 'tpl.php';

//  系统数组
$_Y = [];
$_Y['ip'] = GetIp();
$_user = [];

if($_SESSION['uid'])
{
    $_user = $db->getrow('SELECT * FROM '.Table('user').' WHERE id = '.$_SESSION['uid']);
	if(!$_user || !$_user['status'])
	{
		unset($_SESSION['uid']);
		unset($_COOKIE['LoginSessionID']);
		set_cookie('LoginSessionID','');
	}
}
$_uid = intval($_SESSION['uid']);


if (!in_array($m, array('api'))){
    include_once(ROOT_PATH.'module/wap/'.$m.'/'.$c.'.inc.php');
}else{
    include_once(ROOT_PATH.'module/'.$m.'/'.$c.'.inc.php');
}

